import json

class UserEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, User):
            return {"name": obj.name, "psw": obj.psw}
        return json.JSONEncoder.default(self, obj)

    def json_d(obj):
        return {"name111": obj.name, "psw111": obj.psw}



class User:
    pass
user =User('张三',"781")
uj = json.dumps(user,cls=UserEncoder)
print(uj)




uj = json.dumps(user,default=User.json_d)
print(uj)

aaa = json.loads(uj,object_hook=User.json_l)
print(type(aaa),aaa)